// app.js
App({
    onShow() {
        var that=this;
        var userdata = wx.getStorageSync('userdata');
        console.log(userdata);
        if (userdata == '') {
            wx.showModal({
                title: '提示',
                content: '您还未登录，请先登录',
                success(res) {
                    if (res.confirm) {
                        wx.getUserProfile({
                            desc: '用于小程序',
                            success(res) {
                                var userdata = {
                                    username: res.userInfo.nickName,
                                    avatar: res.userInfo.avatarUrl
                                };
                                wx.login({
                                    success: (result) => {
                                        wx.request({
                                            url: 'https://www..space/login',
                                            method: "GET",
                                            data: {
                                                code: result.code
                                            },
                                            success: (result) => {
                                                console.log(result)
                                                userdata.id=result.data.openid;
                                                wx.request({
                                                    url: 'https://www..space/login/postUserInfo',
                                                    data: userdata,
                                                    method: 'POST',
                                                    success: (res) => {
                                                        wx.setStorage({
                                                            key: "userdata",
                                                            data: userdata,
                                                            success() {
                                                                console.log("上传成功");
                                                            }
                                                        })
                                
                                                    }
                                                })
                                            }
                                        })
                                    }
                                })
                            
                            }
                        })
                    } else if (res.cancel) {
                        console.log('用户点击取消')
                    }
                }
            })


        }
    }
})